package cn.com.czpb.client.module.news.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.com.czpb.client.R;
import cn.com.czpb.client.model.news.ChildsBean;

/**
 * Created by Administrator on 2018/1/8.
 */

public class NewsColumsViewAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<ChildsBean> childlist;

    public NewsColumsViewAdapter(Context mContext, List<ChildsBean> childlist) {
        this.mContext = mContext;
        mInflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.childlist = childlist;
    }

    @Override
    public int getCount() {
        return childlist.size();
    }

    @Override
    public Object getItem(int position) {
        return childlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_city_top, null);
            holder.mImage=(ImageView)convertView.findViewById(R.id.top_view_nanning_item_iv);
            holder.mTitle=(TextView)convertView.findViewById(R.id.top_view_nanning_item_tv);
            holder.root = (LinearLayout) convertView.findViewById(R.id.top_view_nanning_item_root);
            convertView.setTag(holder);
        }else{
            holder=(ViewHolder)convertView.getTag();
        }
        Glide.with(mContext).load(childlist.get(position).getLogo()).crossFade().into((ImageView)holder.mImage);
        holder.mTitle.setText(childlist.get(position).getCnname());
        return convertView;
    }

    private static class ViewHolder {
        private TextView mTitle ;
        private ImageView mImage;
        private LinearLayout root;
    }
}
